package com.example.androidtest_pagerstrip;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;

public class MainActivity extends ActionBarActivity {

	private List<Fragment> fragmentPages;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		fragmentPages = new ArrayList<Fragment>();
		List<String> titleList = new ArrayList<String>();
		titleList.add("第一页");
		titleList.add("第二页");
		titleList.add("第三页");
		titleList.add("第四页");
		for (String title : titleList) {
			fragmentPages.add(PagerFragment.create(title));
		}
		ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
		vp.setAdapter(adapter);
	}
	
	FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {
		
		@Override
		public int getCount() {
			return fragmentPages.size();
		}
		
		@Override
		public Fragment getItem(int arg0) {
			return fragmentPages.get(arg0);
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return ((PagerFragment)fragmentPages.get(position)).getText();
		}
		
	};
}
